import ComponentBase from "../BASE/ComponentBase";
import { Message } from "../Message/Message";
import MessageCenter from "../Message/MessageCenter";
import BUI from "../UIS/BUI";
import MUI from "../UIS/MMUI/MUI";
import BUIManager from "./BUIManager";
import ManagerBase from "./ManagerBase";




const {ccclass, property} = cc._decorator;

@ccclass
export default class UIManager extends ManagerBase{

   
    UIState:number=0;
YuanGong: ComponentBase[] = [];
    messageType="UIManager"

 
    GUI: cc.Node;
    
    
 



public changeUI(state:number){
let BUIM=this.node.getChildByName("BUIManager")
let CUI=this.node.getChildByName("CUIManager")
let SUI1=this.node.getChildByName("shopUI")
let SUI2=this.node.getChildByName("NWshop");
let MMUI=this.node.getChildByName("magicUI").getComponent(MUI)
let a=[["UIManager","GUIManager"]];
let WF=this.node.getChildByName("WFace")
this.UIState=state;

switch (this. UIState) {
    
    
   
    case -1:BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=true; this.GUI.active=true;SUI1.active=false;SUI2.active=false;WF.active=false;
    cc.find("Canvas/thingsManager/Day").active=false;
        break;
    
    
    case 0:BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=false;;this.GUI.active=false;SUI1.active=false;SUI2.active=false;WF.active=false;
    cc.find("Canvas/thingsManager/Day").active=false;
        break;
  
    
            case 1:BUIM.getChildByName("BUI").active=true; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=false;this.GUI.active=false;SUI1.active=false;SUI2.active=false;WF.active=false;
            BUIM.getChildByName("BUI").getComponent(BUI).TNST();
            cc.find("Canvas/thingsManager/Day").active=false;
            break;
            
            case 2:BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=true;CUI.getChildByName("yesno").children[1].active=true;this.GUI.active=true;SUI1.active=false;SUI2.active=false;WF.active=false;
            cc.find("Canvas/thingsManager/Day").active=false;
            break;
            case 2.5:BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=true;CUI.getChildByName("yesno").children[1].active=true;this.GUI.active=false;SUI1.active=false;SUI2.active=false;WF.active=true;
            cc.find("Canvas/thingsManager/Day").active=false;
            break;
            case 3:BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=false;this.GUI.active=false;SUI1.active=true;SUI2.active=false;WF.active=false;
            cc.find("Canvas/thingsManager/Day").active=true; 
            break;
            case 3.5: BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=false;this.GUI.active=false;SUI1.active=false;SUI2.active=true;WF.active=false;
            cc.find("Canvas/thingsManager/Day").active=true; 
            break;
            case 4: BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=false;this.GUI.active=false;SUI1.active=false;WF.active=false;
            BUIM.getChildByName("BUI").getComponent(BUI).TNST();MMUI.open();
            break;
            
            
            
            case 5:BUIM.getChildByName("BUI").active=false; CUI.getChildByName("yesno").children[0].active=false;CUI.getChildByName("yesno").children[1].active=false;;this.GUI.active=false;SUI1.active=false;WF.active=true;
            
            
            break;
            
            default:BUIM.getChildByName("BUI").active=false;
            break;
    }
}










start(){
   MessageCenter.addReceive(this);
   function findNodeInScene(node: cc.Node, targetName: string): cc.Node | null {
    if (node.name === targetName) {
        return node;
    }
    for (let i = 0; i < node.childrenCount; i++) {
        const child = node.children[i];
        const result = findNodeInScene(child, targetName);
        if (result) {
            return result;
        }
    }
    
    return null;
 }
 let rootNode = cc.director.getScene().getChildByName("Canvas");
 
 const targetNode = findNodeInScene(rootNode, "GUIManager"); // 假设要查找的节点名为"TargetNodeName"
 if (targetNode) {
     // 找到了目标节点
     console.log("找到了目标节点");
 } else {
     // 没有找到目标节点
     console.log("没有找到目标节点");
 }
    
   this.GUI=targetNode; 




             this.addReceive(this.node.getChildByName("BUIManager").getComponent(BUIManager))
      
    
         this.changeUI(-1);
      




 }















ReceiveMessage(message: Message){
   
 if(message.Type=="UIManager")
   
   this.DO(message)
}


DO(message: Message){
    let BUI=this.node.getChildByName("BUIManager")
let CUI=this.node.getChildByName("CUIManager")
    if(message.Command=="change"){
        this.changeUI(message.Content)
    
    
    
    
    }}
   






















}
























